package collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合只能存放引用类型元素,并且存放的就是元素的引用(地址)
 */
public class CollectionDemo3 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        Point p = new Point(1,2);
        c.add(p);//将p变量的值(地址)存入集合

        System.out.println("p:"+p);//(1,2)
        System.out.println("c:"+c);//[(1,2)]

        p.setX(2);
        System.out.println("p:"+p);//(2,2)
        System.out.println("c:"+c);//[(2,2)]

        doSome(p,c);
        System.out.println("p:"+p);//(5,2)
        System.out.println("c:"+c);//[(6,7)]
    }

    public static void doSome(Point p,Collection c){
        p.setX(5);
        p = new Point(6,7);
        c.clear();
        c = new ArrayList();
        c.add(p);
    }
}






